package com.yanyi.music.service.impl;

import com.yanyi.music.dao.RankMapper;
import com.yanyi.music.domain.Rank;
import com.yanyi.music.service.RankService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class RankServiceImpl implements RankService {
    @Autowired
    private RankMapper rankMapper;

    @Override
    public int deleteByPrimaryKey(Long id) {
        return rankMapper.deleteByPrimaryKey(id);
    }

    @Override
    public int insert(Rank record) {
        return rankMapper.insert(record);
    }

    @Override
    public int insertSelective(Rank record) {
        return rankMapper.insertSelective(record);
    }

    @Override
    public Rank selectByPrimaryKey(Long id) {
        return rankMapper.selectByPrimaryKey(id);
    }

    @Override
    public int updateByPrimaryKeySelective(Rank record) {
        return rankMapper.updateByPrimaryKeySelective(record);
    }

    @Override
    public int updateByPrimaryKey(Rank record) {
        return rankMapper.updateByPrimaryKey(record);
    }

    @Override
    public int selectScoreSum(Integer songListId) {
        return rankMapper.selectScoreSum(songListId);
    }

    @Override
    public int selectRankNum(Integer songListId) {
        return rankMapper.selectRankNum(songListId);
    }

    /**
     * 计算平均分
     */
    @Override
    public int rankOfSongListId(Integer songListId) {
        int rankNum = rankMapper.selectRankNum(songListId);
        if(rankNum==0){
            return 5;
        }
        return rankMapper.selectScoreSum(songListId)/rankNum;
    }
}
